function getQueryStringFromForm(form) {
	var query = '';
	$('input', form).each(function(index, element) {
		if(query == '')	query = element.name+"="+element.value;
		else query += '&'+element.name+"="+element.value;
		//element.value = '';
	});
	$('textarea', form).each(function(index, element) {
		if(query == '')	query = element.name+"="+element.value;
		else query += '&'+element.name+"="+element.value;
		element.value = '';
	});
	$('select', form).each(function(index, element) {
		if(query == '')	query = element.name+"="+element.value;
		else query += '&'+element.name+"="+element.value;
	});
	return query;
}
$(document).ready(function() {
	$('.ajaxform').submit(function(data) {
		var query = getQueryStringFromForm(this);
		var url = AppData.base_url+$(this).attr('action');
		var div = $('.output',this);
		$.ajax({url:url,
			type:"POST",
			data:query,
			success:function(data){
				div.html(data);
			}
		});
		return false;
	});
	$('.comment_form').each(function(){
		$(this).submit(function(data) {
			var query = getQueryStringFromForm(this);
			var curr_form = this;
			$.ajax({url:AppData.base_url+"welcome/post",
				type:"POST",
				data:query,
				success:function(data) {
					$('.comments',$(curr_form).parent()).append("<div class='commentpost'><b>me: </b>"+data+"</div>");
				},
				error:function() {
					var parent = $(curr_form).parent();
					$('.comments',parent).append("<div class='error' style='color:#ff0000;'>Error occured!</div>");
					$('.error',parent).fadeOut(3000);
				}
			});
			return false;
		});
	});
	$('.my_tabs').each(function() {
		var divs = new Array();
		var i = 0;
		$('li', this).each(function() {
			divs[i] = $(this).attr('tabid');
			$(this).attr('tabIndex', i);
			i++;
		});
		var tabObj = new TabObject(this, divs);
		$('li', this).each(function() {
			$(this).click(function() {
				tabObj.click($(this).attr('tabIndex'));
			});
		});
	});
	$('.jbutton').button();
});
function TabObject(tab_div, content_divs) {
	this.tab_div = tab_div;
	this.content_divs = content_divs;
	this.selectedIndex = $(this.tab_div).attr('default');
	this.click(this.selectedIndex);
}
TabObject.prototype.click = function(index) {
	var i;
	for(i=0; i < this.content_divs.length;i++) {
		$('#'+this.content_divs[i]).hide();
	}
	$('#'+this.content_divs[index]).show();
	this.selectedIndex = index;
	i = 0;
	$('li', this.tab_div).each(function() {
		if(i==index) {
			$(this).attr('class', 'selected');
		}else{
			$(this).attr('class', 'unselected');
		}
		i++;
	});
};
function invite(container, link) {
	$.ajax({url:AppData.base_url+link,
		type:"POST",
		success:function(data) {
			$(container).parent().append('invite sent successfully.'+data);
		}
	});
	return false;
}
function showforgetPswd() {
	$('#trans_layer').height($(document).height());
	$('#trans_layer').show();
	$('#forget_pswd').show();
}
function hideforgetPswd() {
	$('#trans_layer').hide();
	$('#forget_pswd').hide();
	return false;
}